/*
============================================================================
 Name        : PopMenu.h
 Author      : WB
 Version     :
 Copyright   : 益盟软件
 Description : CPopMenu declaration
============================================================================
*/

#ifndef POPMENU_H
#define POPMENU_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <BITSTD.H>
#include "Global.h"

class CFbsBitmapDevice;

class MenuListener
{
public:
	virtual TBool OnMenuEvent(TInt menuId) = 0;

	virtual void DynInitMenu() = 0;
};

/**
*  CPopMenu
* 
*/
class CPopMenu : public CBase
{
public:
	~CPopMenu();

	static CPopMenu* NewL(const TInt& aId,const TDesC& aText);

	static CPopMenu* NewLC(const TInt& aId,const TDesC& aText);

	static CPopMenu* NewL(const TInt& aId,const TInt& aResId);

private:
	CPopMenu();

	void ConstructL(const TInt& aId,const TDesC& aText);

public:
	//new functions
	void SetParent(	CPopMenu* aMenuParent){m_pMenuParent = aMenuParent;}

	void SetListener(MenuListener* aListener){m_menuListener = aListener;}

	void SetPopup(TBool aBool);
	
	TBool IsPopup();

	void OnSize(TInt aPosX = 0, TInt aPosY = 0, TPopupMenuPosition aPosition = TOPLEFT);

	void Append(CPopMenu* menuItem);

	void ChangeMenuItem(TInt id,TInt newId,const TDesC& newTxt);

	void OnDraw(CFbsBitGc& g)const;

	void DrawSubMenu(CFbsBitGc& g)const;

	void DrawArrowButton(CFbsBitGc& g)const;

	TBool OnKeyDown(TInt keyCode);

	TBool NeedDrawAll(){return m_bRepaintAll;}

	void SetNeedDrawAll(TBool aRepaintAll){m_bRepaintAll = aRepaintAll;}

	void GetMenuText(const TInt& id,TDes& aText);
	
	TBool OnMouseDown(const TPoint& aPt);
	
	TBool OnMouseUp(const TPoint& aPt);

	void SetAtvIndex(TInt n);

	inline TRect GetRect() {return m_Rect;}

public:
	TInt		m_nId;
	TBuf<16>	m_strText;

	RPointerArray<CPopMenu>	m_subMenu;

	TBool		m_bIsPop;
	TInt		m_nMaxWidth;
	
	TInt		m_nAtvIndex;
	TInt		m_nBgIndex;
	TBool		m_bScroll;

	TInt		m_nLines;
	TRect		m_RectMenu;
	TRect		m_RectUpArrow;
	TRect		m_RectDownArrow;
	TRect		m_Rect;

	CPopMenu* m_pMenuParent;
	MenuListener* m_menuListener;
	TBool		m_bRepaintAll;

	TBool		m_bUpArrawPressed;
	TBool		m_bDownArrawPressed;
};

#endif // POPMENU_H
